package com.mt.baseinfo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mt.baseinfo.dao.resume.BaseDataDictDao;
import com.mt.baseinfo.dao.schema.EventsStatementsSummaryByDigestDao;
import com.mt.baseinfo.entity.BaseDataDict;
import com.mt.baseinfo.entity.EventsStatementsSummaryByDigest;
import com.mt.baseinfo.enums.DataSourceType;
import com.mt.baseinfo.mult.DataSource;
import com.mt.baseinfo.service.EventsStatementsSummaryByDigestService;
import com.mt.baseinfo.until.BeanConvertUtils;
import com.mt.baseinfo.vo.DigestVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service

public class EventsStatementsSummaryByDigestServiceImpl extends ServiceImpl<EventsStatementsSummaryByDigestDao, EventsStatementsSummaryByDigest> implements EventsStatementsSummaryByDigestService {

    @Override
    @DataSource(value = DataSourceType.DB2)
    public List<DigestVo> executesMost() {
        //SELECT DIGEST_TEXT,COUNT_STAR,FIRST_SEEN,LAST_SEEN FROM events_statements_summary_by_digest ORDER BY COUNT_STAR DESC
        QueryWrapper<EventsStatementsSummaryByDigest> wrapper = new QueryWrapper<>();
        wrapper.select("DIGEST_TEXT","COUNT_STAR","FIRST_SEEN","LAST_SEEN").orderByDesc("COUNT_STAR");
        List<EventsStatementsSummaryByDigest> list = this.baseMapper.selectList(wrapper);
        List<DigestVo> vos = BeanConvertUtils.convertList(list, DigestVo.class);
        if(CollectionUtils.isEmpty(vos)){
            return Collections.EMPTY_LIST;
        }
        return vos;
    }
}
